import request from "@/utils/request";
import {
  ProjectSpecialAccountEditForm,
  ProjectSpecialAccountAuditForm,
  ProjectSpecialAccountPaymentEditForm,
} from "./types";
const currentSystem = localStorage.getItem("usertypeName");

/**
 * 获取专户分页
 *
 * @param data
 */
export function QuerySpecialAccountList(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccount/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccount/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccount/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccount/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccount/page`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccount/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 申请专户
 * @param data
 * @returns
 */
export function CreateProjectSpecialAccount(data: ProjectSpecialAccountEditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccount/create`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccount/create`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccount/create`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccount/create`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccount/create`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccount/create`;
  }
  return request({
    url: `/api/v1/manager/projectspecialaccount/create`,
    method: "post",
    data: data,
  });
}

/**
 * 获取专户详情
 */
export function GetProjectSpecialAccount(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccount/${id}/form`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccount/${id}/form`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccount/${id}/form`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccount/${id}/form`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccount/${id}/form`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccount/${id}/form`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取专户详情
 */
export function GetProjectSpecialAccountByProjectId(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccount/detail/project/${id}`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccount/detail/project/${id}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccount/detail/project/${id}`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccount/detail/project/${id}`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccount/detail/project/${id}`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccount/detail/project/${id}`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 删除专户
 */
export function DeleteProjectSpecialAccount(ids: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccount/${ids}`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccount/${ids}`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccount/${ids}`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccount/${ids}`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccount/${ids}`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccount/${ids}`;
  }
  return request({
    url: url,
    method: "delete",
  });
}

/**
 * 审核专户
 */
export function AuditProjectSpecialAccount(data: ProjectSpecialAccountAuditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccount/audit`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccount/audit`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccount/audit`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccount/audit`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccount/audit`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccount/audit`;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 修改审核信息
 */
export function UpdateAuditProjectSpecialAccount(data: ProjectSpecialAccountAuditForm) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccount/updateAuditInfo`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccount/updateAuditInfo`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccount/updateAuditInfo`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccount/updateAuditInfo`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccount/updateAuditInfo`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccount/updateAuditInfo`;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 获取收支分页
 *
 * @param data
 */
export function QuerySpecialAccountPaymentList(data: any) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccount/page_payment`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccount/page_payment`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccount/page_payment`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccount/page_payment`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccount/page_payment`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccount/page_payment`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}
/**
 * 创建专户收支信息
 * @param data
 * @returns
 */
export function CreateProjectSpecialAccountPayment(data: ProjectSpecialAccountPaymentEditForm) {
  return request({
    url: `/api/v1/sysuser/projectspecialaccountpayment/create`,
    method: "post",
    data: data,
  });
}

/**
 * 获取专户收支详情
 */
export function GetProjectSpecialAccountPayment(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/projectspecialaccountpayment/${id}/form`;
      break;
    case "Corp":
      url = `/api/v1/corp/projectspecialaccountpayment/${id}/form`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/projectspecialaccountpayment/${id}/form`;
      break;
    case "Manager":
      url = `/api/v1/manager/projectspecialaccountpayment/${id}/form`;
      break;
    case "Commander":
      url = `/api/v1/commander/projectspecialaccountpayment/${id}/form`;
      break;
    default:
      url = `/api/v1/sysuser/projectspecialaccountpayment/${id}/form`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 更新专户收支信息
 */
export function UpdateProjectSpecialAccountPayment(data: ProjectSpecialAccountPaymentEditForm) {
  return request({
    url: `/api/v1/sysuser/projectspecialaccountpayment/` + data.id,
    method: "put",
    data: data,
  });
}

/**
 * 删除专户收支信息
 */
export function DeleteProjectSpecialAccountPayment(id: number) {
  return request({
    url: `/api/v1/sysuser/projectspecialaccountpayment/${id}`,
    method: "delete",
  });
}

/**
 * 导出明细
 */
export function ExportPayment(query: any) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectspecialaccount/export_payment";
      break;
    case "Corp":
      url = "/api/v1/corp/projectspecialaccount/export_payment";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectspecialaccount/export_payment";
      break;
    case "Commander":
      url = "/api/v1/commander/projectspecialaccount/export_payment";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/projectspecialaccount/export_payment/";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
    responseType: "arraybuffer",
  });
}
